var janename = ["car","group"];
for (var i=0; i<janename.length; i++){
    var $sbj =  $("#swiperitf");
    var childdiv=$('<div class="swiper-slide swiper-slide-color1"></div>');        //创建一个子div
    childdiv.text(janename[i]);
    $sbj.append(childdiv);
}
var snum;
if (janename.length < 6){
    snum = janename.length;
}else{
    snum = 6;
}
var s_index;
var d_index;
var click_status = 0;
var mySwiper1 = new Swiper ('.swiper-container-1', {
    direction: 'vertical',
    // loop:true,
    speed: 200,
    slidesPerView: snum,
    mousewheelControl: true,
    //autoplay:6000,
    //autoplayDisableOnInteraction: true,
    onClick: function(sdata, event){
        console.log(sdata);
        // d_index = sdata.clickedIndex;
        if (click_status === 0){
            console.log(sdata);
            s_index = sdata.clickedIndex;
            var divtxt = sdata.slides[s_index];
            console.log($(divtxt).text());   //获取div间的数据
            $('.dd').removeClass('dd');
            $(divtxt).addClass('dd')
        }else{
            layer.msg('正在请求数据，稍后');
        }
    }
});

$("#itf_add").on('click', function () {
     var itf_add_con = '<form class="layui-form" action=""><div class="layui-form-item" style="margin-bottom:0"><label class="layui-form-label" style="width:auto">接口名称</label><div class="layui-input-block" style="margin-left:100px"><input id="itf_name" type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input"></div></div></form>';
    layer.msg(
        content=itf_add_con,
        {
            time: 200000,
            area: ['300px', '140px'],
            //200s后自动关闭
            btn: ['确定', '取消'],
            success: function (layero) {
                var btn = layero.find('.layui-layer-btn');
                var btntrue = layero.find('.layui-layer-btn0');
                btn.css('text-align', 'center');
                btntrue.on('click', function () {
                    var i_itf_name = $("#itf_name").val();
                    if (i_itf_name === ""){
                        layer.msg("未输入内容，添加无效！")
                    }else{
                        mySwiper1.appendSlide('<div class="swiper-slide">' +  i_itf_name + '</div>');
                        if (mySwiper1.params.slidesPerView < 6){
                            mySwiper1.params.slidesPerView=mySwiper1.params.slidesPerView +1;
                        }
                        snum += 1;
                        mySwiper1.update(true);
                    }
                })
         }
    });
});

$("#itf_del").on('click', function () {
    mySwiper1.removeSlide(mySwiper1.clickedIndex);
    snum -=1;
    console.log(snum,22222222);
    if (snum < 6){
        mySwiper1.params.slidesPerView=mySwiper1.params.slidesPerView - 1;
        mySwiper1.update();
    }
});